<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>开发一个模块管理引擎</title>
</head>
<body>
    <script>
        let module = (function(){
            const moduleList = [];
            function define(name,modules,action){
                // 模块依赖
                modules.map((m,i) => {
                    modules[i] = moduleList[m];
                });
                // 模块添加
                moduleList[name] = action.apply(null,modules);
            }
            return {define};
        })();
        module.define('hd',[],function(){
            return{
                first(arr){
                    return arr[0];
                },
                max(arr,key){
                    return arr.sort((a,b) => a[key] - b[key])[0];
                }
            }
        });
        module.define('lesson',['hd'],function(hd){
            let data = [
                {"name" : 'js' ,'price' : 199},
                {"name" : 'vue' ,'price' : 299},
            ];
            console.log(hd.max(data,'price'));
        });



        module.define('a',[],function(){
            return{
                site : "kdsjflskadfjsldkf"
            }
        });
        module.define('b',['a'],function(a){
            a.site = "哈哈哈哈哈哈哈";
        });
        module.define('c',['a'],function(a){
            // 在b中改变了a的site，所以在c中打印的是改变之后的site
            console.log(a.site);
        });
    </script>
</body>
</html>